'use strict';
/*-----------时间--------*/
import moment from 'moment';
moment.locale('zh-cn');
/*----------mysql初始化-------------*/
import * as mysql from 'mysql';
import YAML from 'yamljs';
const Settings = YAML.load('settings.yaml');
const MYSQL = Settings.MYSQL;
const mysql_host = MYSQL.host;
const mysql_user = MYSQL.user;
const mysql_password = MYSQL.password;
const mysql_port = MYSQL.port;
const mysql_database = MYSQL.database;
var pool = mysql.createPool({
	connectionLimit: 10,
	host: mysql_host,
	port: mysql_port,
	user: mysql_user,
	password: mysql_password,
	database: mysql_database
});
/*----------------------------------------------------*/
/*----------------数据库处理函数部分----------*/
/*----------------------------------------------------*/
/**创建数据表
 * 
 * @param {string} tableName  表名称
 * @param {string} params 表参数
 */
function CreateTable(tableName: string, params: string) {
	//CREATE TABLE Persons(id int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255));
	let createTablesql = `CREATE TABLE ${tableName} (${params}) DEFAULT CHARACTER SET = utf8`
	// console.log(`${new Date().toLocaleString()}`,createTablesql.toString());
	return new Promise((resolve, reject) => {
		pool.query(createTablesql, function (err: Error | null, result: any) {
			// console.log(`${new Date().toLocaleString()}`,err)
			// console.log(`${new Date().toLocaleString()}`,result)
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT ERROR] - ', err.message);
				reject(err);
			} else {
				resolve(true);
			}
		});
	})
}

function QueryNeededParamsWithCondition(tableName: string, condition: string) {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${condition}`;
	// console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err.message);
			} else {
				resolve(result);
			}
		});
	})
}

function TableIsExists(tableName: string) {
	return new Promise((resolve, reject) => {
		let isexistssql = `SELECT table_name FROM information_schema.TABLES WHERE table_name = '${tableName}'`
		// let isexistssql=`SHOW TABLES LIKE "%${tableName}%";`
		// console.log(`${new Date().toLocaleString()}`,isexistssql.toString());
		pool.query(isexistssql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result != null && result.toString() != '' && result.length > 0) {
					resolve(true);
				} else {
					console.log(`${new Date().toLocaleString()}`, "[TABLE IS EXISTS]-" + result);
					reject();
				}
			}
		});
	});
}

/**
 * 查询不重复的字段
 * @param {*} tableName 
 * @param {*} keys 
 */
function QueryDistinctFieldWhereCondition(tableName: string, keys: string, condition: string) {
	let selectSql = `SELECT DISTINCT ${keys} FROM ${tableName} WHERE ${condition}`;
	if (condition == "" || condition == undefined || condition == null) {
		selectSql = `SELECT DISTINCT ${keys} FROM ${tableName}`;
	}
	// console.log(`${new Date().toLocaleString()}`, selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	});
}

/**查询某条记录是否存在
 * 
 * @param {*} tableName 表名
 * @param {*} primaryKey 键名
 * @param {*} primaryValue 键值
 */
function FieldIsExists(tableName: string, primaryKey: string, primaryValue: string) {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${primaryKey} = ${primaryValue} `;
	// console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length === 0) {
					resolve(false);
				} else {
					// console.log(`${new Date().toLocaleString()}`,result)
					resolve(true);
				}
			}
			// console.log(`${new Date().toLocaleString()}`,'------------------------------------------------------------');
		});
	})
}
function FieldIsExistsWithCondition(tableName: string, condition: string) {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${condition}`;
	// console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(true);
				} else {
					resolve(false);
				}
			}
			// console.log(`${new Date().toLocaleString()}`,'------------------------------------------------------------');
		});
	})
}

/**查询某条记录是否存在
 * 
 * @param {*} tableName 表名
 * @param {*} primaryKey 键名
 * @param {*} primaryValue 键值
 */
function FieldDoesNotExists(tableName: string, primaryKey: string, primaryValue: string) {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${primaryKey} = ${primaryValue} `;
	// console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length === 0) {
					resolve(true);
				} else {
					// console.log(`${new Date().toLocaleString()}`,result)
					reject(`数据存在`)
				}
			}
			// console.log(`${new Date().toLocaleString()}`,'------------------------------------------------------------');
		});
	})
}
/**增加某数据库的数据
 * 
 * @param {string} tableName 表名
 * @param {string} primaryKeys 参数名KEY1,KEY2,....
 * @param {*} paramDatas 数据VALUE1，VALUE2,....
 */
function InsertParamsIntoTable(tableName: string, primaryKeys: string, paramDatas: string) {
	//	INSERT INTO Persons(LastName, Address) VALUES('Wilson', 'Champs-Elysees')
	let addSql = `INSERT INTO ${tableName} (${primaryKeys}) VALUES (${paramDatas})`;
	// console.log(`${new Date().toLocaleString()}`, '\n[INSERT] ' + addSql);
	return new Promise((resolve, reject) => {
		pool.query(addSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[INSERT err] - ', err.message);
				reject(err);
			} else {
				resolve(true);

			}
		});
	})
}
interface QueryConditionalDataFromTableBackResult {
	code: number,
	data: { name: string, age: number }[], //数组里面的对象类型，这里使用的是类型
	message: string
}
/**查询满足条件的数据
 * 
 * @param {*} tableName 表名
 * @param {*} condition 条件
 */
function QueryConditionalDataFromTable(tableName: string, condition: string): Promise<Array<any>> {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${condition}`;
	// console.log(`${new Date().toLocaleString()}`, selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				resolve(result);
			}
		});
	});
}
/**查询满足条件的数据
 * 
 * @param {*} tableName 表名
 * @param {*} condition 条件
 */
function QueryConditionalDataFromTableResoveNull(tableName: string, condition: string): Promise<Array<any> | null> {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${condition}`;
	// console.log(`${new Date().toLocaleString()}`, selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(result);
				} else {
					resolve(null);
				}
			}
		});
	});
}

function descTables(tableName: string) {
	let selectSql = `DESC ${tableName}`;
	// console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	});
}
/** 查询满足条件的数据
 * @param {string} tableName 表名
 * @param {string} primaryKey 键名
 * @param {*} primaryValue 值
 */
function QueryNeededParamsFromTable(tableName: string, primaryKey: string, primaryValue: string): Promise<Array<any> | string> {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${primaryKey} = ${primaryValue} `;
	// console.log(`${new Date().toLocaleString()}`, selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: mysql.queryCallback | undefined) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err.message);
			} else {
				if (Array.isArray(result) && result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	});
}
/**查询满足条件的count条数据数据
 * 
 * @param {string} tableName 表名
 * @param {string} primaryKey 键名
 * @param {*} primaryValue 值
 */
function QueryNeededParamsLimitFromTable(tableName: string, primaryKey: string, primaryValue: string | number | null, count: number) {
	let selectSql = `SELECT * FROM ${tableName} WHERE ${primaryKey} = ${primaryValue} LIMIT ${count}`;
	//console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (Array.isArray(result) == true && result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	});
}
function DropTable(tableName: string) {
	let selectSql = `DROP TBALE ${tableName}`;
	//console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				resolve(true);
			}
		});
	});
}
/*
 * 
 * @param {string} tableName 表名
 * @param {Array} callback (err,params)-->if(err==null),返回查询结果
 */
function QueryAllParamsFromTable(tableName: string) {
	let selectSql = `SELECT * FROM ${tableName}`;
	//console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[SELECT err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	})
}
/**删除符合条件的某一行数据
 * 
 * @param {string} tableName 表名
 * @param {string} primaryKey 键名
 * @param {*} primaryValue 键值
 */
function DeletParamsFromTable(tableName: string, condition: string | null | undefined) {
	let deletSql = `DELETE FROM  ${tableName} WHERE  ${condition}`;
	if (condition == null || condition == undefined) {
		deletSql = `DELETE FROM  ${tableName}`
	}
	// console.log(`${new Date().toLocaleString()}`, deletSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(deletSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				resolve(true);
			}
		});
	});
}

function DeletParamsFromTableWithCondition(tableName: string, condition: string): Promise<boolean> {
	let deletSql = `DELETE FROM  ${tableName} WHERE  ${condition}`;
	//console.log(`${new Date().toLocaleString()}`,deletSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(deletSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				resolve(true);
			}
		});
	});
}
//update tablename set '列名1' = '属性值', '列名2' = '属性值', '列名3' = '属性值' where '主键名' = '属性值';
/**修改符合条件的数据
 * UPDATE ${tableName} SET ${params} WHERE  ${primaryKey} = ${primaryValue}
 * @param {string} tableName 表名
 * @param {string} primaryKey 键名
 * @param {*} primaryValue 键值
 * @param {string} params 参数
 */
function UpdateParamsIntoTable(tableName: string, primaryKey: string, primaryValue: string, params: string) {
	let updateSql = `UPDATE ${tableName} SET ${params} WHERE  ${primaryKey} = ${primaryValue}`;
	//console.log(`${new Date().toLocaleString()}`,updateSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(updateSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				resolve(true);
			}
		});
	});
}
/**
 * 修改符合条件的数据UPDATE ${tableName} SET ${params} WHERE  ${condition}
 * @param {string} tableName 表名
 * @param {string} condition 条件
 * @param {string} params 参数
 */
function UpdateParamsIntoTableWhereCondition(tableName: string, condition: string, params: string) {
	let updateSql = `UPDATE ${tableName} SET ${params} WHERE ${condition}`;
	// console.log(`${new Date().toLocaleString()}`,updateSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(updateSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				resolve(true);
			}
		});
	});
}
/**
 * 修改符合条件的数据UPDATE ${tableName} SET ${params} WHERE  ${condition}
 * @param {string} tableName 表名
 * @param {string} condition 条件
 * @param {string} params 参数
 */
function UpdateParamsIntoTableNoCondition(tableName: string, params: string) {
	let updateSql = `UPDATE ${tableName} SET ${params}`;
	// console.log(`${new Date().toLocaleString()}`,updateSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(updateSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(true);
				} else {
					resolve(true);
				}

			}
		});
	});
}

/**
 * 
 * @param {*} tableName 表名
 * @param {*} key 键
 * @param {*} value 值
 * @returns 
 */
function UpdateValueIntoTable(tableName: string, key: string, value: string | number | null) {
	let updateSql = `UPDATE ${tableName} SET ${key}=${value}`;
	// console.log(`${new Date().toLocaleString()}`, updateSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(updateSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(true);
				} else {
					resolve(true);
				}

			}
		});
	});
}
/**
 * 
 * @param {*} tableName 表名
 * @param {*} key 键
 * @param {*} value 值
 * @returns 
 */
function UpdateMultipleParamsIntoTable(tableName: string, keys: string[], values: string[], condition: string) {
	let params = "";
	for (let index = 0; index < keys.length; index++) {
		params += `,${keys[index]}=${values[index]}`;
	}
	let updateStr = params.substring(1, params.length);
	let updateSql = `UPDATE ${tableName} SET ${updateStr} WHERE ${condition}`;
	// console.log(`${new Date().toLocaleString()}`, updateSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(updateSql, function (err: Error | null, result: any) {
			if (err) {
				console.log(`${new Date().toLocaleString()}`, '[DELETE err] - ', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(true);
				} else {
					resolve(true);
				}

			}
		});
	});
}

/**
 * 查询表满足条件的包含多少条记录
 * @param {string} tableName 表名
 * @param {string} primaryKey 键名
 * @param {*} primaryValue 键值
 */
function SelectCountFromTable(tableName: string, primaryKey: string, primaryValue: string | number | null) {
	//select count(f_masterSn) from t_roller_slaver;
	let lastsql = `SELECT COUNT(${primaryKey}) FROM ${tableName} WHERE  ${primaryKey} = ${primaryValue}`;
	// console.log(`${new Date().toLocaleString()}`,lastsql);
	return new Promise((resolve, reject) => {
		if (primaryKey !== undefined && primaryValue !== undefined) {
			pool.query(lastsql, function (err: Error | null, result: any) {
				if (err) {
					console.log(`${new Date().toLocaleString()}`, 'Select Count from table:', err.message);
					resolve(err);
				} else {
					let obj = result[0];
					//console.log(`${new Date().toLocaleString()}`,obj);
					let key = Object.keys(obj);
					let count = obj[key[0]];
					//console.log(`${new Date().toLocaleString()}`,key);
					resolve(count);
				}
			});
		} else {
			reject();
		}
	});
}

/**
 * 查询满足条件的数据条数
 * @param {*} tableName 表名
 * @param {*} primaryKey 键名
 * @param {*} condition 条件
 */
function SelectCountWithConditionFromTable(tableName: string, primaryKey: string, condition: string) {
	//select count(f_masterSn) from t_roller_slaver;
	let lastsql = `SELECT COUNT(${primaryKey}) FROM ${tableName} WHERE  ${condition}`;
	//	console.log(`${new Date().toLocaleString()}`,lastsql);
	return new Promise((resolve, reject) => {
		if (primaryKey !== undefined && condition !== undefined) {
			pool.query(lastsql, function (err: Error | null, result: any) {
				if (err) {
					console.log(`${new Date().toLocaleString()}`, 'Select Count from table:', err.message);
					reject(err);
				} else {
					let obj = result[0];
					//console.log(`${new Date().toLocaleString()}`,obj);
					let key = Object.keys(obj);
					let count = obj[key[0]];
					//console.log(`${new Date().toLocaleString()}`,key);
					resolve(count);
				}
			});
		} else {
			reject();
		}
	});
}

/**查询最后一条记录
 * 
 * @param {*} tableName 表名
 */
function SelectLastOneParams(tableName: string, condition: string, idName: string): Promise<Array<any>> {
	let lastsql = `SELECT * FROM ${tableName} WHERE ${condition} order by ${idName} DESC limit 1 `;
	//console.log(`${new Date().toLocaleString()}`,lastsql.toString());
	return new Promise((resolve, reject) => {
		pool.query(lastsql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'Select LastOneParams', err.message);
				reject(err);
			} else {
				if (result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	});
}
/**
 * 
 * @param {*} tableAName 表A名称
 * @param {*} tableBName 表B名称
 * @param {*} AKeys A返回值键名 *为全部字段
 * @param {*} BKeys B返回值键名 *为全部字段
 * @param {*} conditions 关联判断条件
 * @example select a.name,a.local,a.channelNameArray, b.CSQ,b.IMEI,b.CCID,b.LBS,b.channel,b.status,b.lastValue,b.t from t_user_bind a join t_gprs_ctrl b on a.deviceId = b.id and a.tel='11111111111';
 */
function QueryConditionalAJoinB(tableAName: string, tableBName: string, AKeys: string, BKeys: string, conditions: string) {
	let selectSql = `SELECT ${AKeys},${BKeys} from ${tableAName} a join ${tableBName} b on ${conditions}`;
	// console.log(`${new Date().toLocaleString()}`,selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				// console.table(result)
				if (result.length > 0) {
					resolve(result);
				} else {
					reject(`参数不存在`);
				}
			}
		});
	});
}

/**获取传感器历史数据条目数
 * 
 * @param {*} tableName 
 * @param {*} updt 
 * @param {*} downdt 
 */
function GetHistoryDataLenth(tableName: string, updt: number, downdt: number, condition: string) {
	// SELECT * FROM t_irr_fer_log WHERE (t BETWEEN 1630541896000 AND 1630570696000) AND deviceType='MIX_PUMP';
	let selectsql = `SELECT * FROM ${tableName} WHERE (t BETWEEN ${downdt} AND ${updt}) AND ${condition}`;
	if (condition == undefined || condition == "" || condition == null) {
		selectsql = `SELECT * FROM ${tableName} WHERE t BETWEEN ${downdt} AND ${updt}`;
	}
	// console.log(`${new Date().toLocaleString()}`, selectsql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectsql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				resolve(result.length);
			}
		});
	});
}

/**
 * 
 * @param {string} tableName 表名
 * @param {number} updt 时间上限
 * @param {number} downdt 时间下限
 * @param {number} offset 偏移量
 * @param {number} limit 查询数量
 */
function SelectHistoryDatas(tableName: string, updt: number, downdt: number, offset: number, limit: number, condition: string) {
	//SELECT * FROM t_irr_fer_log WHERE (t BETWEEN 1630541896000 AND 1630570696000) AND deviceType='MIX_PUMP' LIMIT 0,5;
	let selectsql = `SELECT * FROM ${tableName} WHERE (t BETWEEN ${downdt} AND ${updt}) AND ${condition} order by t desc LIMIT ${offset},${limit}`;
	if (condition == undefined || condition == "" || condition == null) {
		selectsql = `SELECT * FROM ${tableName} WHERE t BETWEEN ${downdt} AND ${updt} order by t desc LIMIT ${offset},${limit} `;
	}
	// console.log(`${new Date().toLocaleString()}`, selectsql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectsql, function (err: Error | null, result: any) {
			if (err) {
				// console.log(`${new Date().toLocaleString()}`,'[SELECT err] - ', err.message);
				reject(err);
			} else {
				resolve(result);
			}
		});
	});
}
/**查询满足条件的数据
 * 
 * @param {*} tableName 表名
 * @param {*} condition 条件
 * @param {*} callback  (err,params)-->if(err==null),返回查询结果
 */
function QueryConditionalAnyDataFromTable(tableName: string, keys: string, condition: string): Promise<any> {
	let selectSql = `SELECT ${keys} FROM ${tableName} WHERE ${condition}`;
	// console.log(selectSql.toString());
	return new Promise((resolve, reject) => {
		pool.query(selectSql, function (err, result) {
			if (err) {
				console.log('[SELECT err] - ', err.message);
				reject(err);
			} else {
				resolve(result);
			}
		});
	});
}
export = {
	CreateTable,
	QueryNeededParamsWithCondition,
	QueryConditionalDataFromTableResoveNull,
	TableIsExists,
	QueryDistinctFieldWhereCondition,
	FieldIsExists,
	FieldIsExistsWithCondition,
	FieldDoesNotExists,
	InsertParamsIntoTable,
	QueryConditionalDataFromTable,
	descTables,
	QueryNeededParamsFromTable,
	QueryNeededParamsLimitFromTable,
	DropTable,
	QueryAllParamsFromTable,
	DeletParamsFromTable,
	DeletParamsFromTableWithCondition,
	UpdateParamsIntoTable,
	UpdateParamsIntoTableWhereCondition,
	UpdateParamsIntoTableNoCondition,
	UpdateValueIntoTable,
	UpdateMultipleParamsIntoTable,
	SelectCountFromTable,
	SelectCountWithConditionFromTable,
	SelectLastOneParams,
	QueryConditionalAJoinB,
	GetHistoryDataLenth,
	SelectHistoryDatas,
	QueryConditionalAnyDataFromTable
}